import request from '@/utils/request'

const basePath = '/jpower-system'

/**
 * @description: 查询所有功能树
 * @param {*} parentId
 * @return {*}
 */
export function getListFun() {
  return request({
    url: basePath + '/core/function/listTree',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

/**
 * @description:
 * @param {*} parentId
 * @return {*}
 */
export function getListMenu() {
  return request({
    url: basePath + '/core/function/listMenuTree',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

/**
 * @description: 创建菜单
 * @param {*} params
 * @return {*}
 */
export function createdFuntion(params) {
  return request({
    url: basePath + '/core/function/add',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    params
  })
}

/**
 * @description: 删除条目
 * @param {*} ids
 * @return {*}
 */
export function removeItem(ids) {
  return request({
    url: basePath + '/core/function/delete',
    method: 'delete',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    params: { ids }
  })
}

/**
 * @description: 更新
 * @param {*} params
 * @return {*}
 */
export function updataItem(params) {
  return request({
    url: basePath + '/core/function/update',
    method: 'put',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    params
  })
}

export function getRoleByRole(roleIds) {
  return request({
    url: basePath + '/core/function/queryUrlIdByRole',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    params: { roleIds }
  })
}

/**
 * @description: 根据父节点查询子节点功能
 * @param {*} params
 * @return {*}
 */
export function getChildren(params) {
  return request({
    url: basePath + '/core/function/listByParent',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    params
  })
}

export function getChildrenBtn(id) {
  return request({
    url: basePath + '/core/function/listBut',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    params: { id }
  })
}

export function lazyAllmenus(parentId) {
  return request({
    url: basePath + '/core/function/lazyTree',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    params: { parentId }
  })
}
